package com.example.consumer.controller;

import com.example.consumer.service.TestService;
import com.example.entity.UserTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author tianzhuang
 * @version 1.0
 * @date 2021/11/7 23:23
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/send")
    public String sendMessage() {
        for (int i = 0; i < 10000; i++) {
            testService.sendMessage();
        }
        return "发送完成"+new Date();
    }

    /**
     * work 模式
     *
     * @return
     */
    @GetMapping("/sendUser")
    public String sendUser() {
        UserTest user = new UserTest();
        user.setId(1);
        user.setName("tianzhuang");
        user.setPassword("123456");
        testService.sendMessage(user);
        return "发送完成"+new Date();
    }

    /**
     *  订阅模式
     * @return
     */
    @GetMapping("/sendUserExchange")
    public String sendUserExchange() {
        UserTest user = new UserTest();
        user.setId(1);
        user.setName("tianzhuang");
        user.setPassword("123456");
        user.setDate(new Date());
        testService.sendExchangeMessage(user);
        return "发送完成"+new Date();
    }


    /**
     * 路由模式
     * @param
     */
    @GetMapping("/sendUserExchangeByKey")
    public String sendUserExchangeByKey() {
        UserTest user = new UserTest();
        user.setId(1);
        user.setName("tianzhuang");
        user.setPassword("123456");
        testService.sendExchangeMessageByKey(user);
        return "发送完成"+new Date();
    }


    /**
     * 通配符模式
     * @param
     */
    @GetMapping("/sendUserExchangeByTopic")
    public String sendUserExchangeByTopic() {
        UserTest user = new UserTest();
        user.setId(1);
        user.setName("tianzhuang");
        user.setPassword("123456");
        user.setDate(new Date());
        testService.sendExchangeMessageByTopic(user);
        return "发送完成"+new Date();
    }
}
